﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using SMIS.Dals;
using SMIS.Entities;

namespace SMIS
{
    public partial class FormStaff : Form
    {
        public FormStaff()
        {
            InitializeComponent();
        }

        private void FormStaff_Load(object sender, EventArgs e)
        {
            List<Staff> staffs = Dal4Staff.SearchAllStaffs();
            gvStaffs.DataSource = staffs;

            CommonUtil.BindData4ComboBox(cboDepart, Dal4Staff.GetDeparts(), "DName", "DID");
            //DataTable dtSelectedDepart = Dal4Staff.GetDeparts();
            //cboDepart.DataSource = dtSelectedDepart;
            //cboDepart.DisplayMember = "DName";
        }

        private void button3_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        //【高月 2013-4-1-232027】修改员工信息按钮事件
        private void button1_Click(object sender, EventArgs e)
        {
            if(gvStaffs.SelectedRows.Count==0)
            {
                MessageBox.Show("请选择要修改的行！","提示");
            }
            else
            {
                Staff selectedStaff = gvStaffs.SelectedRows[0].DataBoundItem as Staff;
                ModifyStaff modifyStaff = new ModifyStaff();
                modifyStaff.MdfName = selectedStaff.SName;
                modifyStaff.MdfSex = selectedStaff.Sex_Field;
                modifyStaff.MdfJobName = selectedStaff.JobName;
                modifyStaff.MdfDepName = selectedStaff.DepName;
                modifyStaff.MdfPosition = selectedStaff.Position;
                modifyStaff.MdfMajor = selectedStaff.Major;
                modifyStaff.MdfEduBgd = selectedStaff.EducationBackground_Field;
                modifyStaff.MdfPlace = selectedStaff.Place;
                modifyStaff.MdfBirthday = selectedStaff.Birthday;
                modifyStaff.MdfStartWorkingDate = selectedStaff.StartWorkingDate;
                modifyStaff.MdfDatesEmployed = selectedStaff.DatesEmployed;
                modifyStaff.MdfRemark = selectedStaff.Remark;
                modifyStaff.MdfID = selectedStaff.SID;

                
                modifyStaff.ShowDialog();
            }
        }


        //【高月 2013-4-1-224652】按部门筛选条件查询出员工信息按钮事件
        private void button4_Click(object sender, EventArgs e)
        {
            Staff staff=new Staff();
            staff.DepName = cboDepart.Text;
            List<Staff> selectedStaffs = Dal4Staff.SearchSelectedDepStaffs(staff);
            gvStaffs.DataSource = selectedStaffs;
        }


        //【高月 2013-4-7-225137】删除员工信息按钮事件
        private void button2_Click(object sender, EventArgs e)
        {
            if (gvStaffs.SelectedRows.Count == 0)
                MessageBox.Show("请选择要删除的行！", "提示");
            else
            {
                Staff staff = gvStaffs.SelectedRows[0].DataBoundItem as Staff;
                if (MessageBox.Show("确定要删除此员工信息？", "确认提示", MessageBoxButtons.OKCancel,
                        MessageBoxIcon.Question) == DialogResult.OK)
                {
                    if (Dal4Staff.DeleteSelectedStaff(staff) == true)
                        MessageBox.Show("恭喜你删除员工信息成功！", "提示");
                    else
                        MessageBox.Show("删除员工信息失败，请先删除与此员工相关的收入信息", "提示");
                }
            }
        }
    }
}
